package com.sharif.cn.local.publish;

import com.sharif.cn.local.publish.reactive.BusinessSubscriber;
import com.sharif.cn.local.publish.reactive.DecoratingSubscriber;
import com.sharif.cn.local.publish.reactive.SimplePublisher;
import com.sharif.cn.local.publish.reactive.SubscriptionAdapter;

import java.io.IOException;

public class LocalReactivePublish {

    SimplePublisher simplePublisher;

    public LocalReactivePublish() throws IOException, InterruptedException {
        BusinessSubscriber businessSubscriber = new BusinessSubscriber(10);
        DecoratingSubscriber decoratingSubscriber = new DecoratingSubscriber(businessSubscriber);
        decoratingSubscriber.setMaxRequest(10);
        SubscriptionAdapter subscriptionAdapter = new SubscriptionAdapter(decoratingSubscriber);
        decoratingSubscriber.onSubscribe(subscriptionAdapter);
        simplePublisher = new SimplePublisher();
        simplePublisher.subscribe(decoratingSubscriber);
    }

    public void publish(Object object)
    {
        simplePublisher.publish(object);
    }
}
